
export default {
  setImageryLayerShow,
  addSingleTileLayer
}

/**
 * 设置图层显示
 * @param {*} layerIds 图层id
 */
function setImageryLayerShow (layerIds) {
  const imageryLayer = this._getImageryLayer()
  Object.keys(imageryLayer).forEach((id) => {
    imageryLayer[id].show = layerIds.includes(id)
  })
}
/**
 * 添加单张瓦片图层
 * @param {*} config.url 瓦片图层地址 必传
 * @param {Array} config.position 瓦片图层位置范围 [west, south, east, north] 可选
 * @returns {Object} 返回添加的图层对象
 */
function addSingleTileLayer (config) {
  const { url = '', position = [] } = config || {}
  const [west, south, east, north] = position
  if (!url) {
    throw Error('addSingleTileLayer: url is required')
  }
  const options = { url }
  if (position.length) {
    Object.assign(options, {
      rectangle: Cesium.Rectangle.fromDegrees(west, south, east, north)
    })
  }
  const provider = new Cesium.SingleTileImageryProvider(options)
  const imageryLayer = this.viewer.imageryLayers.addImageryProvider(provider)
  return imageryLayer
}